package com.ruoyi.project.module.ljw;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.HeEventReport;
import com.ruoyi.project.service.IHeEventReportService;

import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

import static com.ruoyi.common.security.utils.SecurityUtils.getLoginUser;

/**
 * 事件上报信息Controller
 * 
 * @author ruoyi
 * @date 2023-09-02
 */
@RestController
@RequestMapping("/ljw/shouye")
public class LjwShouYeController extends BaseController
{
    @Autowired
    private IHeEventReportService heEventReportService;

    /**
     * 查询事件上报信息列表
     */

    @GetMapping("/list")
    public TableDataInfo list(HeEventReport heEventReport)
    {

        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        /*if(!heEventReport.getReportFiller().equals("001")&&!heEventReport.getReportFiller().equals("002")){
            heEventReport.setReportFillerId(sysUser.getUserId());
        }*/
        heEventReport.setReportFiller(null);
       /* if(heEventReport.getReportEventState().equals("03")){
            String time= DateUtils.parseDateToStr("yyyy-MM-dd",DateUtils.getNowDate());
            heEventReport.setNote1(time);
        }*/

        List<HeEventReport> list = heEventReportService.selectHeEventReportListByMonth(heEventReport);

        return getDataTable(list);
    }
    @GetMapping("/levellist")
    public TableDataInfo levelList(HeEventReport heEventReport)
    {
        LoginUser loginUser = getLoginUser();

        SysUser sysUser = loginUser.getSysUser();
       /* if(!heEventReport.getReportFiller().equals("001")&&!heEventReport.getReportFiller().equals("002")){
            heEventReport.setReportFillerId(sysUser.getUserId());
        }*/
        heEventReport.setReviewStatus("02");
        /*heEventReport.setReviewStatus("02");*/
        heEventReport.setReportFiller(null);
        String[] level={"01","02","03","04"};
        ArrayList<Integer> list= new ArrayList<Integer>();
        String time= DateUtils.parseDateToStr("yyyy-MM-dd",DateUtils.getNowDate());
        heEventReport.setNote1(time);
        for(int i=0;i<level.length;i++){
            heEventReport.setResultsEventClassification(level[i]);

            List<HeEventReport> rlist = heEventReportService.selectHeEventReportListByMonth(heEventReport);
            /*List<HeEventReport> rlist = heEventReportService.selectHeEventReportList(heEventReport);*/
            if(rlist.size()>0){

                list.add(rlist.size());
            }else{

                list.add(0);
            }
        }

        return getDataTable(list);
    }
    @GetMapping("/monthlist")
    public TableDataInfo monthList(HeEventReport heEventReport)
    {
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();


        /*if(!heEventReport.getReportFiller().equals("001")&&!heEventReport.getReportFiller().equals("002")){
            heEventReport.setReportFillerId(sysUser.getUserId());
        }*/
        heEventReport.setReviewStatus("02");
        heEventReport.setReportFiller(null);
        String year= DateUtils.parseDateToStr("yyyy",DateUtils.getNowDate());
        String[] month={"01-01","02-01","03-01","04-01","05-01","06-01","07-01","08-01","09-01","10-01","11-01","12-01"};
        ArrayList<Integer> list= new ArrayList<Integer>();
        for(int i=0;i<month.length;i++){
            heEventReport.setNote1(year+"-"+month[i]);
            List<HeEventReport> rlist = heEventReportService.selectHeEventReportListByMonth(heEventReport);
            if(rlist.size()>0){
                list.add(rlist.size());
            }else{

                list.add(0);
            }
        }

        return getDataTable(list);
    }
    @GetMapping("/overviewlist")
    public TableDataInfo overviewList(HeEventReport heEventReport)
    {
        List<Integer> tongJiList=new ArrayList<Integer>();
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        /*  if(!heEventReport.getReportFiller().equals("001")&&!heEventReport.getReportFiller().equals("002")){
            heEventReport.setReportFillerId(sysUser.getUserId());
        }*/
        HeEventReport heEventReport1=new HeEventReport();
        /*if(heEventReport.getReportFiller().equals("002")){
            *//*heEventReport1.setReportDepartment(String.valueOf(sysUser.getDeptId()));*//*
        }*/
        heEventReport.setReviewStatus("02");
        heEventReport1.setReviewStatus("02");
        heEventReport.setReportFiller(null);
        String time= DateUtils.parseDateToStr("yyyy-MM-dd",DateUtils.getNowDate());
        heEventReport.setNote1(time);
        List<HeEventReport> list = heEventReportService.selectHeEventReportListByMonth(heEventReport);
        tongJiList.add(list.size());

        heEventReport1.setNote1(time);
        /*heEventReport1.setReportFillerId(heEventReport.getReportFillerId());*/
        //上报人数
        List<String> slist = heEventReportService.getDistinctReportFiller(heEventReport1);
        //部门数
        List<Long> dlist = heEventReportService.getDistinctReportDepartment(heEventReport1);

        tongJiList.add(dlist.size());
        tongJiList.add(slist.size());
        heEventReport.setReportEventState("03");
        List<HeEventReport> wlist = heEventReportService.selectHeEventReportListByMonth(heEventReport);
        heEventReport.setReportEventState("04");
        List<HeEventReport> ylist = heEventReportService.selectHeEventReportListByMonth(heEventReport);
        tongJiList.add(wlist.size());
        tongJiList.add(ylist.size());
        return getDataTable(tongJiList);
    }

    /**
     * 导出事件上报信息列表
     */

    @Log(title = "事件上报信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HeEventReport heEventReport)
    {
        List<HeEventReport> list = heEventReportService.selectHeEventReportList(heEventReport);
        ExcelUtil<HeEventReport> util = new ExcelUtil<HeEventReport>(HeEventReport.class);
        util.exportExcel(response, list, "事件上报信息数据");
    }

    /**
     * 获取事件上报信息详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(heEventReportService.selectHeEventReportById(id));
    }

    /**
     * 新增事件上报信息
     */
    @RequiresPermissions("project:report:add")
    @Log(title = "事件上报信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HeEventReport heEventReport)
    {
        return toAjax(heEventReportService.insertHeEventReport(heEventReport));
    }

    /**
     * 修改事件上报信息
     */
    @RequiresPermissions("project:report:edit")
    @Log(title = "事件上报信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeEventReport heEventReport)
    {
        return toAjax(heEventReportService.updateHeEventReport(heEventReport));
    }

    /**
     * 删除事件上报信息
     */
    @RequiresPermissions("project:report:remove")
    @Log(title = "事件上报信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(heEventReportService.deleteHeEventReportByIds(ids));
    }
}
